/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package cn.knet.sp.ncrm.modules.sys.region.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import cn.knet.sp.ncrm.common.persistence.Page;
import cn.knet.sp.ncrm.common.service.CrudService;
import cn.knet.sp.ncrm.modules.sys.region.dao.RegionDao;
import cn.knet.sp.ncrm.modules.sys.region.entity.Region;

/**
 * 客户区域Service
 * @author zhangbin
 * @version 2015-08-27
 */
@Service
@Transactional(readOnly = true)
public class RegionService extends CrudService<RegionDao, Region> {

	public Region get(String id) {
		return super.get(id);
	}
	
	public List<Region> findList(Region region) {
		return super.findList(region);
	}
	
	public Page<Region> findPage(Page<Region> page, Region region) {
		return super.findPage(page, region);
	}
	
	@Transactional(readOnly = false)
	public void save(Region region) {
		super.save(region);
	}
	
	@Transactional(readOnly = false)
	public void delete(Region region) {
		super.delete(region);
	}

	public int findDistinctRegion(Region region) {
		return dao.findDistinctRegion(region);
	}


	/**
	 * 查询 固有区域列表
	 * @author zhangbin
	 * @date 2015 /08/31 12:40:37
	 * @param region the region
	 * @return the list
	 */
	public List<Region> findAdminList(Region region) {
		return dao.findAdminList(region);
	}

	@Transactional
	public void saveAdmin(Region region) {
		if (region.getIsNewRecord()){
			region.preInsert();
			region.setId(region.getNumber()); //编号替换为ID
			dao.insertAdmin(region);
		}else{
			region.preUpdate();
			dao.updateAdmin(region);
			dao.updateChild(region);
		}

	}

	public int findChina(Region region) {
		return dao.findChina(region);
	}
}